package com.servlet;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Shop_model;

/**
 * Servlet implementation class Delete_ser
 */
@WebServlet("/Delete_ser")
public class Delete_ser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Delete_ser() {
		super();

	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession(true);

		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("utf-8");
		Writer out = response.getWriter();

		String id = request.getParameter("index");
		System.out.println(id);

		if (session.getAttribute("list") == null) {
			out.write("当前购物车已为空！");
		} else {
			List<Shop_model> list = (List<Shop_model>) session.getAttribute("list");
			int castId=Integer.valueOf(id);
			if(list.size()==0){
				
			}else{
				list.remove(castId);
			}
			session.setAttribute("list", list);
			
		}

		//request.getRequestDispatcher("Shop_cart.jsp").forward(request, response);
		//response.sendRedirect("Shop_cart.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
